' (C)2010, Paul
' sql to java converting
' s2j.vbs <sql file>
'
Set arg = WScript.Arguments
const ver = "s2j.vbs v1.01"

f = arg(0)
commSQL="--"
commJava="//"
convert f, f+".java"

Sub convert(ifile, ofile)
  dim fso, i, o, l, nn
  WScript.Echo ifile & " -> " & ofile
  set fso = CreateObject("Scripting.FileSystemObject")
  set i = fso.OpenTextFile(ifile)
  set o = fso.CreateTextFile(ofile, True)

  o.WriteLine(commJava & "File " & ifile &" convert at "& date &" "& time &" by "& ver)
  o.WriteLine("String sql = ")
  cnt=1
  do while i.AtEndOfStream <> True
    l = i.ReadLine
    o.WriteLine(StrConv(l,cnt))
    cnt = cnt + 1
  loop
  o.WriteLine("")
  i.Close
  o.Close

  'fso.DeleteFile ifile, true
End Sub


'  Java: + "\n <str>"
'  	if len(text)=1 and asc(text)=160 then
'StrConv=replace(StrConv, chr(160), "")
Function StrConv(Text, p_cnt)
  text=replace(text, """", "\""")
  if left(trim(text),2)<>commSql then
    if InStr(ucase(text), "DBMS_OUTPUT") then
      text = commSql + text
    end if
  end if

  if p_cnt=1 then
    StrConv= """" + text + """"
  else
    StrConv= "+ ""\n " + text + """"
  end if	
End Function